package com.hzqy.service.statistics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.commons.utils.SystemConfigUtils;
import com.hzqy.persistence.dao.statistics.ListenDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.service.pms.PmsServiceBean;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.StatDataListenAllVo;
import com.hzqy.web.vo.StatDataListenTop20Vo;
import com.hzqy.web.vo.StatDataListenVo;
import com.hzqy.web.vo.StatDataOneVideoRecordVo;
import com.hzqy.web.vo.statistics.UserListenHistoryVo;
import com.hzqy.web.vo.statistics.user_video_demand.UserVideoDemandVo;

@Service
public class ListenServiceBean extends GenericServiceBean<PmsUserVo, ListenDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private ListenDao listenDao;
	
	@Override
	public ListenDao getEntityDao() {
		return listenDao;
	}
	@Resource
	private PmsServiceBean pmsServiceBean;
	
	public Map<String,Object> selectListenList(StatDataListenVo statDataListenVo, int curPage,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenCount(statDataListenVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sdl_type", statDataListenVo.getF_sdl_type());
			map.put("f_sdl_resolution", statDataListenVo.getF_sdl_resolution());
			map.put("beginDate", statDataListenVo.getBeginDate());
			map.put("endDate", statDataListenVo.getEndDate());
			map.put("monthDate", statDataListenVo.getMonthDate());
			map.put("weekDate", statDataListenVo.getWeekDate());
			map.put("f_sdl_productid", statDataListenVo.getF_sdl_productid());
			List<StatDataListenVo> results = listenDao.selectListenList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenVo>());
		}
		return map;
	}
	
	public Map<String,Object> selectExcelList(StatDataListenVo statDataListenVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenCount(statDataListenVo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sdl_type", statDataListenVo.getF_sdl_type());
			map.put("f_sdl_resolution", statDataListenVo.getF_sdl_resolution());
			map.put("beginDate", statDataListenVo.getBeginDate());
			map.put("endDate", statDataListenVo.getEndDate());
			map.put("monthDate", statDataListenVo.getMonthDate());
			map.put("weekDate", statDataListenVo.getWeekDate());
			map.put("f_sdl_productid", statDataListenVo.getF_sdl_productid());
			List<StatDataListenVo> results = listenDao.selectListenExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenVo>());
		}
		return map;
	}
	
	public Map<String,Object> selectListenTop20List(StatDataListenTop20Vo statDataListenTop20Vo, int curPage,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenTop20Count(statDataListenTop20Vo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sdtl_type", statDataListenTop20Vo.getF_sdtl_type());
			map.put("f_sdtl_resolution", statDataListenTop20Vo.getF_sdtl_resolution());
			map.put("beginDate", statDataListenTop20Vo.getBeginDate());
			map.put("endDate", statDataListenTop20Vo.getEndDate());
			map.put("monthDate", statDataListenTop20Vo.getMonthDate());
			map.put("weekDate", statDataListenTop20Vo.getWeekDate());
			map.put("f_sdtl_productid", statDataListenTop20Vo.getF_sdtl_productid());
			List<StatDataListenTop20Vo> results = listenDao.selectListenTop20List(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenTop20Vo>());
		}
		return map;
	}
	
	public Map<String,Object> selectListenTop20ExcelList(StatDataListenTop20Vo statDataListenTop20Vo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenTop20Count(statDataListenTop20Vo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sdtl_type", statDataListenTop20Vo.getF_sdtl_type());
			map.put("f_sdtl_resolution", statDataListenTop20Vo.getF_sdtl_resolution());
			map.put("beginDate", statDataListenTop20Vo.getBeginDate());
			map.put("endDate", statDataListenTop20Vo.getEndDate());
			map.put("monthDate", statDataListenTop20Vo.getMonthDate());
			map.put("weekDate", statDataListenTop20Vo.getWeekDate());
			map.put("f_sdtl_productid", statDataListenTop20Vo.getF_sdtl_productid());
			List<StatDataListenTop20Vo> results = listenDao.selectListenTop20ExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenTop20Vo>());
		}
		return map;
	}

	public Map<String, Object> selectListenAllList(StatDataListenAllVo statDataListenAllVo, int curPage, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenAllCount(statDataListenAllVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sdta_type", statDataListenAllVo.getF_sdta_type());
			map.put("f_sdta_resolution", statDataListenAllVo.getF_sdta_resolution());
			map.put("beginDate", statDataListenAllVo.getBeginDate());
			map.put("endDate", statDataListenAllVo.getEndDate());
			map.put("monthDate", statDataListenAllVo.getMonthDate());
			map.put("weekDate", statDataListenAllVo.getWeekDate());
			map.put("f_sdta_productid", statDataListenAllVo.getF_sdta_productid());
			List<StatDataListenAllVo> results = listenDao.selectListenAllList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenAllVo>());
		}
		return map;
	}

	public Map<String, Object> selectListenAllExcelList(StatDataListenAllVo statDataListenAllVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = listenDao.selectListenAllCount(statDataListenAllVo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sdta_type", statDataListenAllVo.getF_sdta_type());
			map.put("f_sdta_resolution", statDataListenAllVo.getF_sdta_resolution());
			map.put("beginDate", statDataListenAllVo.getBeginDate());
			map.put("endDate", statDataListenAllVo.getEndDate());
			map.put("monthDate", statDataListenAllVo.getMonthDate());
			map.put("weekDate", statDataListenAllVo.getWeekDate());
			map.put("f_sdta_productid", statDataListenAllVo.getF_sdta_productid());
			List<StatDataListenAllVo> results = listenDao.selectListenAllExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<StatDataListenAllVo>());
		}
		return map;
	}
	
	public Map<String, Object> selectListenHistoryList(PmsUserVo userVo,UserListenHistoryVo UVo, int curPage, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		if(userVo.getParentOrgId() > 0){
			String orgIds = pmsServiceBean.getIndustryAuthorityPmsOrgIds(userVo);
			map.put("orgIds",orgIds);
		}
		map.put("beginDate", UVo.getBeginDate());
		map.put("endDate", UVo.getEndDate());
		map.put("f_cc_companyid",UVo.getF_cc_companyid()); 
		map.put("f_ulh_serverid",UVo.getF_ulh_serverid());
		map.put("f_ulh_cc_name",UVo.getF_ulh_cc_name());
		map.put("f_ulh_servername",UVo.getF_ulh_servername());
		Integer rowCount = listenDao.selectListenHistoryCount(map);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			List<UserListenHistoryVo> results = listenDao.selectListenHistoryList(map);
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_ulh_playtime();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_ulh_playtime());
				}else{
					code=0;
				}
				UserListenHistoryVo uv=results.get(i);
				uv.setF_ulh_play_minut((code/60)+"");
				uv.setF_ulh_playtime(code+"");
				int h=code/3600;
				int m=(code-3600*h)/60;
				int s=code%60;
				String strh="";
				String strm="";
				String strs="";
				if(h==0){
					strh="00";
				}else if(h<10){
					strh="0"+h;
				}else{
					strh=""+h;
				}
				if(m==0){
					strm="00";
				}else if(m<10){
					strm="0"+m;
				}else{
					strm=""+m;
				}
				if(s==0){
					strs="00";
				}else if(s<10){
					strs="0"+s;
				}else{
					strs=""+s;
				}
				uv.setF_ulh_play_hms(strh+":"+strm+":"+strs);
				results.set(i,uv );
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserListenHistoryVo>());
		}
		return map;
	}
	
	public Map<String, Object> selectUserListenHistoryExcelList(PmsUserVo userVo,UserListenHistoryVo UVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		if(userVo.getParentOrgId() > 0){
			String orgIds = pmsServiceBean.getIndustryAuthorityPmsOrgIds(userVo);
			map.put("orgIds",orgIds);
		}
		map.put("beginDate", UVo.getBeginDate());
		map.put("endDate", UVo.getEndDate());
		map.put("f_cc_companyid",UVo.getF_cc_companyid()); 
		map.put("f_ulh_serverid",UVo.getF_ulh_serverid()); 
		map.put("f_ulh_cc_name",UVo.getF_ulh_cc_name());
		map.put("f_ulh_servername",UVo.getF_ulh_servername());
		Integer rowCount = listenDao.selectListenHistoryCount(map);
		map.put("total", rowCount);
		if(rowCount > 0) {
			List<UserListenHistoryVo> results = listenDao.selectListenHistoryExcelList(map);
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_ulh_playtime();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_ulh_playtime());
				}else{
					code=0;
				}
				UserListenHistoryVo uv=results.get(i);
				uv.setF_ulh_play_minut((code/60)+"");
				uv.setF_ulh_playtime(code+"");
				int h=code/3600;
				int m=(code-3600*h)/60;
				int s=code%60;
				String strh="";
				String strm="";
				String strs="";
				if(h==0){
					strh="00";
				}else if(h<10){
					strh="0"+h;
				}else{
					strh=""+h;
				}
				if(m==0){
					strm="00";
				}else if(m<10){
					strm="0"+m;
				}else{
					strm=""+m;
				}
				if(s==0){
					strs="00";
				}else if(s<10){
					strs="0"+s;
				}else{
					strs=""+s;
				}
				uv.setF_ulh_play_hms(strh+":"+strm+":"+strs);
				results.set(i,uv );
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserListenHistoryVo>());
		}
		return map;
	}
	
	/**
	 * 宁波个性化统计查询包含维度：客户名称、业务账号、业务账号名称、日统计
	 * @param userVideoDemandVo
	 * @param curPage
	 * @param pageSize
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectListenHistoryPersonaliseNBList(UserVideoDemandVo userVideoDemandVo, int curPage, int pageSize, int statisticalDimension) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		Integer rowCount = 0;
		
		if(statisticalDimension==1){
			map.put("statistical_dimension","f_sduvd_orgId");
		}else if(statisticalDimension==2){
			map.put("statistical_dimension","f_sduvd_serverId");
		}else if(statisticalDimension==3){
			map.put("statistical_dimension","f_sduvd_serverName");
		}else if(statisticalDimension==5){
			map.put("statistical_dimension","LEFT (f_sduvd_playDate, 10)");
		}
		
		rowCount = listenDao.selectListenHistoryByStatisticalDimensionCount(map);
		
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			
			List<UserVideoDemandVo> results = new ArrayList<UserVideoDemandVo>();
			results = listenDao.selectListenHistoryByStatisticalDimensionList(map);
			
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_sduvd_sumPlayTimes();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_sduvd_sumPlayTimes());
				}else{
					code=0;
				}
				UserVideoDemandVo uvdv=results.get(i);
				uvdv.setF_sduvd_sumPlayTimes(code+"");
				uvdv.setF_sduvd_sumPlayMinut((code/60)+"");
				uvdv.setF_sduvd_sumPlayHour((code/3600)+"");
				results.set(i,uvdv );
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserVideoDemandVo>());
		}
		return map;
	}
	
	/**
	 * 宁波个性化统计数量查询包含维度：客户名称、业务账号、业务账号名称、日统计
	 * @param userVideoDemandVo
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> userListenHistoryCount(UserVideoDemandVo userVideoDemandVo,int statisticalDimension) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		Integer rowCount = 0;
		
		if(statisticalDimension==1){
			map.put("statistical_dimension","f_sduvd_orgId");
		}else if(statisticalDimension==2){
			map.put("statistical_dimension","f_sduvd_serverId");
		}else if(statisticalDimension==3){
			map.put("statistical_dimension","f_sduvd_serverName");
		}else if(statisticalDimension==5){
			map.put("statistical_dimension","LEFT (f_sduvd_playDate, 10)");
		}
		
		rowCount = listenDao.selectListenHistoryByStatisticalDimensionCount(map);
		
		map.put("total", rowCount);
		
		return map;
	}
	
	/**
	 * 宁波个性化统计导出包含维度：客户名称、业务账号、业务账号名称、日统计
	 * @param userVideoDemandVo
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectUserListenHistoryPersonaliseNBExcelList(UserVideoDemandVo userVideoDemandVo,int statisticalDimension) {
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		
		if(statisticalDimension==1){
			map.put("statistical_dimension","f_sduvd_orgId");
		}else if(statisticalDimension==2){
			map.put("statistical_dimension","f_sduvd_serverId");
		}else if(statisticalDimension==3){
			map.put("statistical_dimension","f_sduvd_serverName");
		}else if(statisticalDimension==5){
			map.put("statistical_dimension","LEFT (f_sduvd_playDate, 10)");
		}
		
		List<UserVideoDemandVo> results = new ArrayList<UserVideoDemandVo>();
		
		results = listenDao.selectListenHistoryByStatisticalDimensionExcelList(map);
		
		for(int i=0;i<results.size();i++){
			String  cod=results.get(i).getF_sduvd_sumPlayTimes();
			int code =0;
			boolean flag=true;
			for(int k=0;k<cod.length();k++){
				if (!Character.isDigit(cod.charAt(k))){
					flag=false;
				}
			}
			
			if(flag && !cod.equals("")){
				code =Integer.parseInt(results.get(i).getF_sduvd_sumPlayTimes());
			}else{
				code=0;
			}
			UserVideoDemandVo uvdv=results.get(i);
			uvdv.setF_sduvd_sumPlayTimes(code+"");
			uvdv.setF_sduvd_sumPlayMinut((code/60)+"");
			uvdv.setF_sduvd_sumPlayHour((code/3600)+"");
			results.set(i,uvdv );
		}
		
		map.put("rows", results);
		
		return map;
		
	}
	
	/**
	 * 视频播放考核查询统计
	 * @param userVideoDemandVo
	 * @param curPage
	 * @param pageSize
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectVideoPlayAssessment(UserVideoDemandVo userVideoDemandVo, int curPage, int pageSize, int qualifiedTime) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		Integer rowCount = 0;
		rowCount = listenDao.selectVideoPlayAssessmentCount(map);
		
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			
			List<UserVideoDemandVo> results = new ArrayList<UserVideoDemandVo>();
			results = listenDao.selectVideoPlayAssessmentList(map);
			
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_sduvd_sumPlayTimes();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_sduvd_sumPlayTimes());
				}else{
					code=0;
				}
				UserVideoDemandVo uvdv=results.get(i);
				uvdv.setF_sduvd_sumPlayMinut((code/60)+"");
				if((code/60)>=qualifiedTime){
					uvdv.setF_sduvd_is_qualification("合格");
				}else{
					uvdv.setF_sduvd_is_qualification("不合格");
				}
				results.set(i,uvdv);
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserVideoDemandVo>());
		}
		return map;
	}
	
	/**
	 * 查询视频播放考核数量
	 * @param userVideoDemandVo
	 * @param qualifiedTime
	 * @return
	 */
	public Map<String, Object> selectVideoPlayAssessmentCount(UserVideoDemandVo userVideoDemandVo, int qualifiedTime) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		Integer rowCount = 0;
		rowCount = listenDao.selectVideoPlayAssessmentCount(map);
		
		map.put("total", rowCount);
		
		return map;
	}
	
	/**
	 * 视频播放考核查询统计并进行导出
	 * @param userVo
	 * @param UVo
	 * @param curPage
	 * @param pageSize
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectVideoPlayAssessmentExcelList(UserVideoDemandVo userVideoDemandVo, int qualifiedTime) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("beginDate", userVideoDemandVo.getBeginDate());
		map.put("endDate", userVideoDemandVo.getEndDate());
		map.put("f_sduvd_orgId",userVideoDemandVo.getF_sduvd_orgId()); 
		map.put("f_sduvd_serverId",userVideoDemandVo.getF_sduvd_serverId());
		map.put("f_sduvd_serverName",userVideoDemandVo.getF_sduvd_serverName());
		
		List<UserVideoDemandVo> results = new ArrayList<UserVideoDemandVo>();
		results = listenDao.selectVideoPlayAssessmentExcelList(map);
		
		for(int i=0;i<results.size();i++){
			String  cod=results.get(i).getF_sduvd_sumPlayTimes();
			int code =0;
			boolean flag=true;
			for(int k=0;k<cod.length();k++){
				if (!Character.isDigit(cod.charAt(k))){
					flag=false;
				}
			}
			
			if(flag && !cod.equals("")){
				code =Integer.parseInt(results.get(i).getF_sduvd_sumPlayTimes());
			}else{
				code=0;
			}
			UserVideoDemandVo uvdv=results.get(i);
			uvdv.setF_sduvd_sumPlayMinut((code/60)+"");
			if((code/60)>=qualifiedTime){
				uvdv.setF_sduvd_is_qualification("合格");
			}else{
				uvdv.setF_sduvd_is_qualification("不合格");
			}
			if(uvdv.getF_sduvd_period()==1){
				uvdv.setF_sduvd_periodName("上午");
			}else if(uvdv.getF_sduvd_period()==2){
				uvdv.setF_sduvd_periodName("下午");
			}else{
				uvdv.setF_sduvd_periodName("");
			}
			results.set(i,uvdv);
		}
		map.put("rows", results);
		
		return map;
	}

	public Map<String, Object> selsecVideoRecordAllList(StatDataOneVideoRecordVo statDataOneVideoRecordVo,int curPage,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		int rowCount  = listenDao.selectVideoRecordCount(statDataOneVideoRecordVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("beginDate", statDataOneVideoRecordVo.getBeginDate());
			map.put("endDate", statDataOneVideoRecordVo.getEndDate());
			map.put("f_sdovr_name", statDataOneVideoRecordVo.getF_sdovr_name());
			map.put("f_sdovr_address", statDataOneVideoRecordVo.getF_sdovr_address());
			List<StatDataOneVideoRecordVo> results = listenDao.selectVideoRecordList(map);
			map.put("rows", results);
		}else {
			map.put("rows", new ArrayList<StatDataOneVideoRecordVo>() );
		}
		return map;
	}

	public Map<String, Object> selsecVideoRecordAllExceList(StatDataOneVideoRecordVo statDataOneVideoRecordVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		int rowCount  = listenDao.selectVideoRecordCount(statDataOneVideoRecordVo);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_sdovr_name", statDataOneVideoRecordVo.getF_sdovr_name());
			map.put("f_sdovr_address", statDataOneVideoRecordVo.getF_sdovr_address());
			map.put("beginDate", statDataOneVideoRecordVo.getBeginDate());
			map.put("endDate", statDataOneVideoRecordVo.getEndDate());
			List<StatDataOneVideoRecordVo> results = listenDao.selsecVideoRecordAllExceList(map);
			map.put("rows", results);
		}else {
			map.put("rows", new ArrayList<StatDataOneVideoRecordVo>());
		}
		return map;
	}
	
	/**
	 * 宁波个性化（根据视频名称）统计查询
	 * @param userVo
	 * @param UVo
	 * @param curPage
	 * @param pageSize
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectListenHistoryPersonaliseNBVideoList(PmsUserVo userVo,UserListenHistoryVo UVo, int curPage, int pageSize, int statisticalDimension) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		String designatedOrgs = SystemConfigUtils.getSysConfig("OnDemandTotalTimeStatistics_"+userVo.getOrgId());
		if(designatedOrgs!=null && !"".equals(designatedOrgs)){
			map.put("orgIds",designatedOrgs);
		}else{
			if(userVo.getParentOrgId() > 0){
				String orgIds = pmsServiceBean.getIndustryAuthorityPmsOrgIds(userVo);
				map.put("orgIds",orgIds);
			}
		}
		
		map.put("beginDate", UVo.getBeginDate());
		map.put("endDate", UVo.getEndDate());
		map.put("f_cc_companyid",UVo.getF_cc_companyid()); 
		map.put("f_ulh_serverid",UVo.getF_ulh_serverid());
		map.put("f_ulh_cc_name",UVo.getF_ulh_cc_name());
		map.put("f_ulh_servername",UVo.getF_ulh_servername());
		Integer rowCount = 0;
		
		map.put("statistical_dimension","a1.f_ulh_cc_name");
		
		rowCount = listenDao.selectListenHistoryByViewCount(map);
		
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			
			List<UserListenHistoryVo> results = new ArrayList<UserListenHistoryVo>();
			
			results = listenDao.selectListenHistoryByViewList(map);
			
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_ulh_playtime();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_ulh_playtime());
				}else{
					code=0;
				}
				UserListenHistoryVo uv=results.get(i);
				uv.setF_ulh_play_minut((code/60)+"");
				uv.setF_ulh_playtime(code+"");
				uv.setF_ulh_play_hour((code/3600)+"");
				results.set(i,uv );
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserListenHistoryVo>());
		}
		return map;
	}
	
	/**
	 * 宁波个性化（根据视频名称）统计数量查询
	 * @param userVo
	 * @param UVo
	 * @param statisticalDimension
	 * @return
	 */
	public Map<String, Object> selectListenHistoryPersonaliseNBVideoCount(PmsUserVo userVo,UserListenHistoryVo UVo,int statisticalDimension) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		String designatedOrgs = SystemConfigUtils.getSysConfig("OnDemandTotalTimeStatistics_"+userVo.getOrgId());
		if(designatedOrgs!=null && !"".equals(designatedOrgs)){
			map.put("orgIds",designatedOrgs);
		}else{
			if(userVo.getParentOrgId() > 0){
				String orgIds = pmsServiceBean.getIndustryAuthorityPmsOrgIds(userVo);
				map.put("orgIds",orgIds);
			}
		}
		
		map.put("beginDate", UVo.getBeginDate());
		map.put("endDate", UVo.getEndDate());
		map.put("f_cc_companyid",UVo.getF_cc_companyid()); 
		map.put("f_ulh_serverid",UVo.getF_ulh_serverid());
		map.put("f_ulh_cc_name",UVo.getF_ulh_cc_name());
		map.put("f_ulh_servername",UVo.getF_ulh_servername());
		Integer rowCount = 0;
		
		map.put("statistical_dimension","a1.f_ulh_cc_name");
		
		rowCount = listenDao.selectListenHistoryByViewCount(map);
		
		map.put("total", rowCount);
		
		return map;
	}
	
	/**
	 * 宁波个性化（根据视频名称）统计导出
	 * @param userVo
	 * @param UVo
	 * @return
	 */
	public Map<String, Object> selectUserListenHistoryPersonaliseNBVideoExcelList(PmsUserVo userVo,UserListenHistoryVo UVo,int statisticalDimension) {
		Map<String,Object> map = new HashMap<String, Object>();
		
		String designatedOrgs = SystemConfigUtils.getSysConfig("OnDemandTotalTimeStatistics_"+userVo.getOrgId());
		if(designatedOrgs!=null && !"".equals(designatedOrgs)){
			map.put("orgIds",designatedOrgs);
		}else{
			if(userVo.getParentOrgId() > 0){
				String orgIds = pmsServiceBean.getIndustryAuthorityPmsOrgIds(userVo);
				map.put("orgIds",orgIds);
			}
		}
		
		map.put("beginDate", UVo.getBeginDate());
		map.put("endDate", UVo.getEndDate());
		map.put("f_cc_companyid",UVo.getF_cc_companyid()); 
		map.put("f_ulh_serverid",UVo.getF_ulh_serverid()); 
		map.put("f_ulh_cc_name",UVo.getF_ulh_cc_name());
		map.put("f_ulh_servername",UVo.getF_ulh_servername());
		
		Integer rowCount = 0;
		
		map.put("statistical_dimension","a1.f_ulh_cc_name");
		
		rowCount = listenDao.selectListenHistoryByViewCount(map);
		
		map.put("total", rowCount);
		if(rowCount > 0) {
			
			List<UserListenHistoryVo> results = new ArrayList<UserListenHistoryVo>();
			
			results = listenDao.selectListenHistoryByViewExcelList(map);
			
			for(int i=0;i<results.size();i++){
				String  cod=results.get(i).getF_ulh_playtime();
				int code =0;
				boolean flag=true;
				for(int k=0;k<cod.length();k++){
					if (!Character.isDigit(cod.charAt(k))){
						flag=false;
					}
				}
				
				if(flag && !cod.equals("")){
					code =Integer.parseInt(results.get(i).getF_ulh_playtime());
				}else{
					code=0;
				}
				UserListenHistoryVo uv=results.get(i);
				uv.setF_ulh_play_minut((code/60)+"");
				uv.setF_ulh_playtime(code+"");
				uv.setF_ulh_play_hour((code/3600)+"");
				results.set(i,uv );
			}
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserListenHistoryVo>());
		}
		return map;
	}
	
}
